home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Information / CSMP Digest / volume 1 / csmp-v1-145.txt < prev    next >
Encoding:
Text File  |  1994-12-08  |  44.8 KB  |  1,285 lines  |  [TEXT/R*ch]

  1. C.S.M.P. Digest             Sun, 19 Jul 92       Volume 1 : Issue 145
  2.  
  3. Today's Topics:
  4.  
  5.     The big question...
  6.     Is "WITH anObject DO ..." dangerous in THINK Pascal ?
  7.     Mistake in THINK Pascal manual (boolean operators)
  8.     Think C and ctype
  9.     dynamic 2d arrays in THINK C?
  10.  
  11.  
  12.  
  13. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  14.  
  15. The digest is a collection of article threads from the internet newsgroup
  16. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  17. regularly and want an archive of the discussions.  If you don't know what a
  18. newsgroup is, you probably don't have access to it.  Ask your systems
  19. administrator(s) for details.  (This means you can't post questions to the
  20. digest.)
  21.  
  22. Each issue of the digest contains one or more sets of articles (called
  23. threads), with each set corresponding to a 'discussion' of a particular
  24. subject.  The articles are not edited; all articles included in this digest
  25. are in their original posted form (as received by our news server at
  26. cs.uoregon.edu).  Article threads are not added to the digest until the last
  27. article added to the thread is at least one month old (this is to ensure that
  28. the thread is dead before adding it to the digest).  Article threads that
  29. consist of only one message are generally not included in the digest.
  30.  
  31. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  32. [128.223.8.8] in the directory /pub/mac/csmp-digest.  The most recent issues
  33. are available from sumex-aim.stanford.edu [36.44.0.6] in the directory
  34. /info-mac/digest/csmp.  If you don't have ftp capability, the sumex archive
  35. has a mail server; send a message with the text '$MACarch help' (no quotes)
  36. to LISTSERV@ricevm1.rice.edu for more information.
  37.  
  38. The digest is also available via email.  Just send a note saying that you
  39. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  40. automatically receive each new issue as it is created.  Sorry, back issues
  41. are not available through the mailing list.
  42.  
  43. Send administrative mail to mkelly@cs.uoregon.edu.
  44.  
  45.  
  46. -------------------------------------------------------
  47.  
  48. From: skelmir@rhi.hi.is (Mimir Reynisson)
  49. Subject: The big question...
  50. Date: 15 Jun 92 07:56:26 GMT
  51.  
  52. Now that the facts have come to light etc and Microsoft won the 
  53. look-and-feel suit against Apple. And that seems to be the trend
  54. in the software business. Why not create a set of applications that
  55. look excatly like Word, Excel, etc..? There seems to be a quite a lot of
  56. cases that say that you would not loose in court, and not be fined either.
  57.  
  58. It seems to me that as long as you have a different set of manuals,
  59. they cant touch you.
  60.  
  61. //S&M
  62.  
  63. +++++++++++++++++++++++++++
  64.  
  65. From: fry@tara.harvard.edu (David Fry)
  66. Date: 15 Jun 92 11:23:22 GMT
  67. Organization: Harvard Math Department
  68.  
  69.  
  70. Microsoft has not won the lawsuit with Apple.  A month or so ago
  71. a judge threw out a large portion of Apple's suit, but then he agreed
  72. to reconsider those parts.  Last week the whole issue was postponed
  73. until a future date.  So it's not at all over yet.
  74.  
  75. As for your suggestion to make programs that work exactly like
  76. leading applications, Borland was sued by Lotus for doing this a few
  77. years ago over the spreadsheet Quattro, but I forget the outcome. 
  78. Anyone, anyone? I'm pretty sure Lotus lost.
  79.  
  80.  
  81. David Fry                               fry@math.harvard.EDU
  82. Division of Applied Sciences            fry@huma1.bitnet
  83. Harvard University                      ...!harvard!huma1!fry
  84. Cambridge, MA  02138            
  85.  
  86. +++++++++++++++++++++++++++
  87.  
  88. From: johnston@me.udel.edu (William Johnston)
  89. Date: 15 Jun 92 15:03:00 GMT
  90. Organization: University of Delaware/Department of Mechanical Engineering
  91.  
  92. In article <4945@krafla.rhi.hi.is>, skelmir@rhi.hi.is (Mimir Reynisson) writes...
  93. >Now that the facts have come to light etc and Microsoft won the 
  94. >look-and-feel suit against Apple. And that seems to be the trend
  95. >in the software business. Why not create a set of applications that
  96. >look excatly like Word, Excel, etc..? [...]
  97.  
  98. Blechhh!  I might agree if MS had even come *close* to matching
  99. Apple's look and feel.  Never has so much effort and money been
  100. wasted, in my view.  It doesn't matter how good the Toyota is;
  101. some people, even _most_ people, will end up buying something
  102. cheaper.  Some will even let themselves be swayed (or assuaged)
  103. by a salesman's suggestion that a Chevy is just as good as a 
  104. Toyota, only cheaper.  And for some purposes, that may be true.
  105.  
  106. Nevertheless, one rarely sees the "Toyota" in such a scenario
  107. spending so much effort attacking the claims of a "Chevrolet".
  108. Why?  Because ... not only is such a tactic clearly the act
  109. of a coward/weenie (if you'll forgive my ascribing individual 
  110. traits to a group) but it also serves to legitimize the claims
  111. of the imitator/pretender in the minds of the consumer.
  112.  
  113. The two sides will probably never reach an understanding on
  114. this point, but *my* side-by-side comparisons of Windows and
  115. MacOS never left me wondering which product was the "Toyota",
  116. or rather, which was genuinely innovative and well designed.
  117.  
  118. If the point is still not clear to the boneheads in Apple
  119. management who decided to pursue this wasteful lawsuit,
  120. here in a nutshell is the lesson they should have learned:
  121.  
  122. 1)  Imitation is the highest form of flattery.
  123. 2)  It is a better marketing strategy to exploit the fact
  124.     that one is being imitated than it is to attack the 
  125.     imitator, either legally or by smear tactics.
  126.  
  127. Apple is a big company that has adopted a mix of sales
  128. strategies in the Mac era.  At times, various Apple ad
  129. campaigns have practiced the above lesson effectively;
  130. clearly, not everyone in Apple management agreed with
  131. the Apple vs. MS & HP lawsuit tactic/strategy.
  132.  
  133. In the aftermath of the legal verdicts -- when the dust
  134. finally clears -- Apple shareholders should take a long
  135. look at the outcome and hold those who preached lawsuit
  136. accountable. 
  137.  
  138. I'm a (satisfed) Apple customer;  all that I lost as the 
  139. result of the wasted legal expenses is that I might have 
  140. paid a bit less for Apple products and perhaps benefitted 
  141. from an even faster rate of innovation.  But that's just 
  142. a guess -- who's to say that progree would have come any 
  143. faster if Apple's resources had been directed exclusively 
  144. at R&D and price competitiveness?
  145.  
  146. But if I were an Apple shareholder, I'd be asking tough
  147. questions about the return on investment in legal costs.
  148. If the answer demonstrates the utter stupidity of the
  149. look-and-feel legal misadventure (as I'm sure it will)
  150. I would demand to see heads roll.
  151.  
  152. - -- Bill (johnston@me.udel.edu)
  153.  
  154. +++++++++++++++++++++++++++
  155.  
  156. From: kfischer@mesa.llnl.gov (K. Fischer)
  157. Date: 15 Jun 92 16:29:38 GMT
  158. Organization: LLNL
  159.  
  160. In article <15JUN199210032745@me.udel.edu>, johnston@me.udel.edu (William Johnston) writes:
  161. |>Blechhh!  I might agree if MS had even come *close* to matching
  162. |>Apple's look and feel.  Never has so much effort and money been
  163. |>wasted, in my view.  It doesn't matter how good the Toyota is;
  164. |>some people, even _most_ people, will end up buying something
  165. |>cheaper.  Some will even let themselves be swayed (or assuaged)
  166. |>by a salesman's suggestion that a Chevy is just as good as a 
  167. |>Toyota, only cheaper.  And for some purposes, that may be true.
  168.  
  169. I would *MUCH* rather have the Chevy, thank you very much (and I'm
  170. not talking about computers OR software here).  Just MHO  :^)
  171. Perhaps if you had said "It doesn't matter how good the domestic car
  172. is; some people, even _most_ people, will end up buying something
  173. imported".   :^)
  174.  
  175. - --
  176. Kathleen Fischer
  177. kfischer@mesa.llnl.gov
  178.  
  179. "Is it true, Is it nice, Is it necessary?"  <-- flame proof :^)
  180. DISCLAIMER: Statements expressed here are mine, Mine, MINE!!!
  181.  
  182. +++++++++++++++++++++++++++
  183.  
  184. From: orpheus@reed.edu (P. Hawthorne)
  185. Date: 16 Jun 92 23:45:21 GMT
  186. Organization: Reed College, Portland, Oregon
  187.  
  188.  
  189.   skelmir@rhi.hi.is (Mimir Reynisson) writes...
  190. . Why not create a set of appls that look excatly like Word, Excel...
  191.  
  192.   Retch! Be careful what you wish for, you just might get it.
  193.  
  194.  
  195.   johnston@me.udel.edu (William Johnston) writes:
  196. . I might agree if MS had even come *close* to matching Apple's look and
  197. . feel. Never has so much effort and money been wasted, in my view.
  198.  
  199.   At this point, Bill Gates has more money than he can possibly spend
  200. before he earns that much again. Microslut is worse than the meat trusts,
  201. and should have been dismantled by the Feds in the Eighties. The least the
  202. FTC should do is break the operating system and compiler groups up from the
  203. word processor and spreadsheet groups, and let them fight over who gets the
  204. electronic mail group.
  205.  
  206.   I want to see Gates in front of a Senate committee hearing yesterday,
  207. trying to explain away the body of trust law with some palsy excuses about
  208. standardization and the merits of centrally planned economies. 
  209.  
  210.   Anyone ever see the old movie The Devil and Daniel Webster? Would Gates
  211. be Javis, Scratch himself, or the succubus from over the hills?
  212.  
  213.  
  214.   suitti@ima.isc.com (Stephen Uitti) writes:
  215. . Actually, with System 7, one could claim that Apple has copied the look
  216. . and feel of MS Windows - slow and bloated.
  217.  
  218.   Speaking of Webster, NeXT's programmers must use low end NeXT hardware
  219. for development.
  220.  
  221.  
  222.   Theus (orpheus@reed.edu)
  223.  
  224. +++++++++++++++++++++++++++
  225.  
  226. From: suitti@ima.isc.com (Stephen Uitti)
  227. Organization: Interactive Systems, Cambridge, MA 02138-5302
  228. Date: Tue, 16 Jun 1992 18:42:12 GMT
  229.  
  230. In article <15JUN199210032745@me.udel.edu> johnston@me.udel.edu (William Johnston) writes:
  231. >In article <4945@krafla.rhi.hi.is>, skelmir@rhi.hi.is (Mimir Reynisson) writes...
  232. >>Now that the facts have come to light etc and Microsoft won the 
  233. >>look-and-feel suit against Apple. And that seems to be the trend
  234. >>in the software business. Why not create a set of applications that
  235. >>look excatly like Word, Excel, etc..? [...]
  236. >
  237. >Blechhh!  I might agree if MS had even come *close* to matching
  238. >Apple's look and feel.  Never has so much effort and money been
  239. >wasted, in my view.
  240.  
  241. Actually, with System 7, one could claim that Apple has copied
  242. the look and feel of MS Windows - slow and bloated.
  243.  
  244. I'm considering upgrading from System 7 to System 6.0.7.
  245. I'd still get Truetype for my non-postscript printer, and
  246. could still watch little tiny QuickTime movies...
  247.  
  248. Seriously, I think it's time to rewrite the finder again - this
  249. time, using the Macintosh user interface guidelines to the
  250. letter, and using a development system that isn't so slow and
  251. bloated that you can only develop using a Quadra with 32 MB RAM,
  252. and 600 MB of disk.  The finder should be runable on a Mac Plus
  253. with a 1/2 MB of RAM.  C++ isn't all it was promised to be.
  254.  
  255. Stephen.
  256. suitti@ima.isc.com
  257.  
  258. +++++++++++++++++++++++++++
  259.  
  260. From: major@bbn.com (John Major)
  261. Date: 17 Jun 92 17:09:58 GMT
  262. Organization: Bolt Beranek and Newman Inc., Cambridge MA
  263.  
  264.  
  265. To use Telnet with MacTCP and the Comm Toolbox, use one of the third
  266. party Connection Tools - Versaterm Telnet Tool from Synergy Software,
  267. or TCPak from Advanced Software Concepts (a French gang). They are
  268. both excellent. The MacTCP Tool that comes with MacX I know will only
  269. work with MacX, and now you've told me why - "hardwired for port 6000",
  270. eh?
  271.  
  272. Good luck -
  273. John Major
  274. major@bbn.com
  275. ALINK:D6590
  276. 617/873-8165
  277.  
  278. +++++++++++++++++++++++++++
  279.  
  280. From: bilpin.co.uk (Mark Allerton)
  281. Date: 17 Jun 92 15:51:06 GMT
  282. Organization: SRL Data
  283.  
  284. > As for your suggestion to make programs that work exactly like
  285. > leading applications, Borland was sued by Lotus for doing this a few
  286. > years ago over the spreadsheet Quattro, but I forget the outcome. 
  287. > Anyone, anyone? I'm pretty sure Lotus lost.
  288.  
  289. In fact, Lotus sued Paperback software and *won*, I think you'll find
  290.  
  291. Mark Allerton
  292. UK Macintosh Developer Technical Support
  293.  
  294. ---------------------------
  295.  
  296. From: wstomv@wsinpa01.win.tue.nl (Tom Verhoeff)
  297. Subject: Is "WITH anObject DO ..." dangerous in THINK Pascal ?
  298. Date: 15 Jun 92 12:05:51 GMT
  299.  
  300. In several places (Inside Macintosh, THINK Pascal documentation) I have
  301. read warnings not to rely on addresses to relocatable data structures.
  302.  
  303. For example, if H a is a Handle to some relocatable record R, then
  304.  
  305.     WITH H^^ DO BEGIN
  306.         "do something that might cause R to be relocated" ;
  307.         "modify a field of R"
  308.         END
  309.  
  310. is asking for trouble, because the THINK Pascal compiler determines the
  311. actual address of the record R once upon entry of the WITH-statement.
  312. Relocation of R invalidates that address and, hence, further
  313. references via this address no longer make sense.
  314.  
  315. My question now is:
  316.  
  317.     Does this also hold for WITH-statements applied to objects?
  318.  
  319. The similarity between "WITH anObject DO ..." and the above is that
  320. in THINK Pascal, an object variable is implemented as a Handle (to
  321. the actual object, which resides in a relocatable record on the heap).
  322. Even though you don't write it as such, "WITH anObject DO ..." is
  323. a disguise of "WITH anObjectHandle^^ DO ...".  And how about the
  324. implicit "WITH SELF DO ..." in the body of methods?
  325.  
  326. On the other hand, since the THINK Pascal compiler might incorporate
  327. knowledge about the particular use of WITH on objects, I can imagine
  328. that "WITH anObject DO ..." does not suffer from the same problems
  329. as "WITH H^^ DO ...".  For instance, because once upon entry of the
  330. WITH-statement a Handle to the object is determined (and not a direct
  331. pointer, which gets invalidated by relocation of the object).
  332.  
  333. Can anyone shed some light on this?  I have not been able to find
  334. explicit mention of this in either Inside Mac or the THINK Pascal doc.
  335.  
  336.     Tom
  337. - -- 
  338. INTERNET: wstomv@win.tue.nl  /    Eindhoven University of Technology
  339. VOICE: +31 40 47 41 25      /    Dept of Mathematics & Computing Science
  340. FAX: +31 40 43 66 85       /    PO Box 513, NL-5600 MB Eindhoven, Netherlands
  341.  
  342. +++++++++++++++++++++++++++
  343.  
  344. From: siegel@world.std.com (Rich Siegel)
  345. Date: 15 Jun 92 14:02:05 GMT
  346. Organization: GCC Technologies
  347.  
  348. In article <3542@svin02.info.win.tue.nl> wstomv@win.tue.nl writes:
  349.  
  350. [describes WITH h^^ DO...]
  351.  
  352. >    Does this also hold for WITH-statements applied to objects?
  353.  
  354. Yes. It's also true for the implicit WITH SELF DO in methods, so it's
  355. wise to have a lock method which will stack the object's current state,
  356. move it high, and lock it, and an unlock method which will pop the last
  357. state, and to use these calls at the beginning and end of methods or
  358. around WITH statements.
  359.  
  360. R.
  361. - -- 
  362. - -----------------------------------------------------------------------
  363. Rich Siegel                              Internet: siegel@world.std.com
  364. Software Engineer & Toolsmith
  365. GCC Technologies
  366.  
  367. +++++++++++++++++++++++++++
  368.  
  369. From: wstomv@wsinpa01.win.tue.nl (Tom Verhoeff)
  370. Date: 16 Jun 92 07:48:43 GMT
  371. Organization: Eindhoven Univ. of Technology, The Netherlands
  372.  
  373. In article <3542@svin02.info.win.tue.nl>, wstomv@win.tue.nl writes:
  374. >In several places (Inside Macintosh, THINK Pascal documentation) I have
  375. >read warnings not to rely on addresses to relocatable data structures.
  376. >
  377. >For example, if H a is a Handle to some relocatable record R, then
  378. >
  379. >    WITH H^^ DO BEGIN
  380. >        "do something that might cause R to be relocated" ;
  381. >        "modify a field of R"
  382. >        END
  383. >
  384. >is asking for trouble, because the THINK Pascal compiler determines the
  385. >actual address of the record R once upon entry of the WITH-statement.
  386. >Relocation of R invalidates that address and, hence, further
  387. >references via this address no longer make sense.
  388. >
  389. >My question now is:
  390. >
  391. >    Does this also hold for WITH-statements applied to objects?
  392.              ^^^^
  393. (I admit, "this" is rather vague, but read on.)
  394.  
  395. So far I have had four reactions.  They unanimously---but, as I now
  396. know, incorrectly---claim that
  397.  
  398.     WITH aHandle^^ DO ...
  399. and
  400.     WITH anObject DO ...
  401.  
  402. (including the implicit "WITH SELF DO ..."  surrounding bodies of methods)
  403.  
  404. are EQUALLY dangerous.  Nevertheless, I have evidence to the contrary.
  405. I carried out a little experiment to investigate the matter.  This
  406. experiment is described below.
  407.  
  408. Let me first give a summary of the result (N.B. This applies to
  409. THINK Pascal; it need not apply to other implementations of objects):
  410.  
  411.     Upon entry of "WITH aHandle^^ DO ..." a temporary POINTER
  412.     to the record is determined (once).  Access of an unqualified
  413.     record field in ... involves this temporary pointer to
  414.     determine the address of the field.  Record relocation may
  415.     invalidate this temporary pointer, leading to nasty bugs.
  416.  
  417.     Upon entry of "WITH anObject DO ..." a temporary HANDLE (not
  418.     pointer!) to the object is determined (once).  Access of an
  419.     unqualified instance variable of the object in ... involves
  420.     this temporary handle to determine the address of the instance
  421.     variable.  Record relocation does NOT affect the addressing
  422.     through the temporary handle.  N.B. This does NOT imply that
  423.     there are NO dangers at all with addresses of objects and
  424.     (more importantly) their instance variables (see below).
  425.  
  426. Why would you want to know this?  Because, if you assume that access of
  427. an object's instance variables in a WITH statement is equally
  428. dangerous, then programming with objects becomes a pain.  Too defensive
  429. approaches to objects (such as avoiding WITH statements or, worse,
  430. moving data to high memory and (un)locking etc.), make programs overly
  431. complicated and I consider that even more dangerous.  Fortunately, in
  432. THINK Pascal there is no need to worry that much.  And Symantec should
  433. explain this in their documentation.  (The only hint---if you can call
  434. it that---I have found is on page 37 (top) of the THINK Pascal Object-Oriented
  435. Programming Manual Version 4.  Here, it is suggested that references
  436. to instance variables, even in WITH statements, are resolved dynamically.)
  437.  
  438. Apparently, "WITH anObject DO ..." is implemented slightly less efficiently
  439. than "WITH aHandle^^ DO ...".  The reason to use "WITH anObject DO ...",
  440. however, is not only to simplify the syntactic appearance of your programs.
  441. Consider, for instance, a two dimensional array of objects, such as
  442.     VAR anObjectArray: ARRAY[ 0..9 , 0..9 ] OF CObject ;
  443. then in "WITH anObjectArray[i,j] DO ..." the handle to the object
  444. at coordinates i,j is determined only once and references to its instance
  445. variables in the WITH statement body do NOT involve repeated indexing
  446. in the array.
  447.  
  448. - --------------------------------------------------------------------------
  449. Now for the EXPERIMENT.  It involves the following program:
  450.  
  451.     PROGRAM WithObjectTest ;
  452.  
  453.     TYPE
  454.       CObject = OBJECT
  455.         InstanceVariable: integer ;
  456.         END ; { CObject }
  457.  
  458.       TRecord = RECORD
  459.         Field: integer ;
  460.         END ; { TRecord }
  461.  
  462.       TRecordPtr = ^TRecord ;
  463.       TRecordHandle = ^TRecordPtr ;
  464.  
  465.     VAR
  466.       anObject: CObject ;
  467.       aRecordHandle: TRecordHandle ;
  468.  
  469.     BEGIN { WithObjectTest }
  470.     ShowText ;
  471.  
  472.     new( anObject ) ; { create an instance }
  473.  
  474.     writeln( @anObject.InstanceVariable ) ;
  475.     WITH anObject DO BEGIN
  476.       writeln( InstanceVariable ) ;
  477.       MoveHHi( Handle( anObject ) ) ; { force relocation }
  478.       writeln( InstanceVariable ) ;
  479.       END ; { with }
  480.     writeln( @anObject.InstanceVariable ) ;
  481.     writeln ;
  482.  
  483.     aRecordHandle := TRecordHandle( NewHandle( SizeOf( TRecord ) ) ) ;
  484.       { create a record }
  485.  
  486.     writeln( @aRecordHandle^^.Field ) ;
  487.     WITH aRecordHandle^^ DO BEGIN
  488.       writeln( Field ) ;
  489.       MoveHHi( Handle( aRecordHandle ) ) ; { force relocation }
  490.       writeln( Field ) ;
  491.       END ; { with }
  492.     writeln( @aRecordHandle^^.Field ) ;
  493.  
  494.     END. { WithObjectTest }
  495.  
  496. Sample output in Text window (for one run on my machine):
  497.  
  498.     004C3DC6
  499.     004C3DC6
  500.     004DB5CA
  501.     004DB5CA
  502.  
  503.     004C3F10
  504.     004C3F10
  505.     004C3F10
  506.     004DB5C8
  507.  
  508. Interpretation of output:
  509.  
  510.     It is to be expected that in both blocks the first two addresses
  511.     are equal (no relocation opportunity occurred in between them
  512.     (unless writeln may cause relocation; any comment?)).  The output
  513.     confirms this.
  514.  
  515.     The acid test is whether in each block the last two addresses
  516.     are equal.  Here, we notice a clear difference.
  517.  
  518.     In case of the object (hence, an implicit handle), we see that
  519.     for the second occurrence of the InstanceVariable in the WITH
  520.     statement the correct address is obtained (in spite of the
  521.     preceding relocation, which took place because the last addres
  522.     differs from the first).  This is the way I think it ought to be.
  523.  
  524.     In case of the explicit handle (second block), we see that
  525.     after relocation (which took place because the last address
  526.     differs from the first), the wrong (= old) address of Field
  527.     is obtained.
  528.     (The compiler can hardly be blamed because, in such cases it
  529.     does not know that the "pointer to a pointer" is actually a handle.
  530.     There is no way to write "WITH aHandle DO ...", since aHandle is
  531.     not a record.)
  532.  
  533. Conclusion:
  534.  
  535.     "WITH anObject DO ..." is NOT equally dangerous as
  536.     "WITH aHandle^^ DO ...".
  537.  
  538. [NOTE: If someone can (explain to me how to) disassemble the above
  539. program, then this might provide further insights.]
  540.  
  541. What dangers are still present when using objects?  Well, since they
  542. can be relocated, you should never rely on (the constancy of) their
  543. addresses (or those of their instance variables).  For example, the
  544. following use is DANGEROUS (the context is that of above program):
  545.  
  546.     WITH anObject DO
  547.       BadProc( InstanceVariable ) ;
  548.  
  549. where BadProc is defined by
  550.  
  551.     PROCEDURE BadProc( VAR n: integer ) ;
  552.       BEGIN
  553.       "cause relocation" ;
  554.       n := 0 ;
  555.       END ; { BadProc }
  556.  
  557. The address of the actual parameter passed to BadProc is determined
  558. before the relocation.  The assignment to the actual parameter
  559. occurs after relocation and is based on the obsolete address.
  560.  
  561. It is equally dangerous to do:
  562.  
  563.     BadProc( anObject.InstanceVariable ) ;
  564.  
  565.     WITH aRecordHandle^^ DO
  566.       BadProc( Field ) ;
  567.  
  568.     BadProc( aRecordHandle^^.Field ) ;
  569.  
  570. Thus, this danger has nothing to do with WITH-statements!
  571.  
  572.     Tom
  573. - -- 
  574. INTERNET: wstomv@win.tue.nl  /    Eindhoven University of Technology
  575. VOICE: +31 40 47 41 25      /    Dept of Mathematics & Computing Science
  576. FAX: +31 40 43 66 85       /    PO Box 513, NL-5600 MB Eindhoven, Netherlands
  577.  
  578. +++++++++++++++++++++++++++
  579.  
  580. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  581. Organization: NCRPDA, Curtin University
  582. Date: Wed, 17 Jun 1992 04:04:55 GMT
  583.  
  584. In article <3542@svin02.info.win.tue.nl>, wstomv@wsinpa01.win.tue.nl (Tom Verhoeff) writes:
  585.  
  586. >     Does this also hold for WITH-statements applied to objects?
  587.  
  588. > Can anyone shed some light on this?  I have not been able to find
  589. > explicit mention of this in either Inside Mac or the THINK Pascal doc.
  590.  
  591. Yes, its dangerous.  Lock the object first.  It is documented explicitly as 
  592. dangerous somewhere in the TP manual, I remember reading it, and have been
  593. bitten by it before (ooops :-).
  594.  
  595. Note there are much less obvious senarios that are also dangerous or error
  596. prone.  Here is an example:
  597.  
  598. type theObject=object
  599.     s:str255;
  600.    procedure Ick;
  601.   end;
  602.  
  603. {$S Eeek}
  604. procedure Eeek(s:str255);
  605. begin
  606. end;
  607.  
  608. {$S Main}
  609. procedure theObject.Ick;
  610. begin
  611.   Eeek(s);
  612. end;
  613.  
  614. Eeek can receive a garbage string, even though its a value parameter.  Why?
  615. What happens is that the address of s in the object is pushed, and then 
  616. Eeek is called.  But since Eek is in another segment, it may need loading,
  617. which will invalidate the pointer, before Eeek gets a chance to copy the
  618. string.  Bad news.  Obviously things would be even worse if s was a var 
  619. parameter, since the Eeek could then write garbage to the invalid address.
  620.  
  621. These aren't Symantec's fault, but I have certainly found objects to
  622. be very dangerous, you need to be especially careful with them because
  623. it is so easy to forget that you are referencing handle fields.  Personally
  624. I'd preffer a different (safer) implementation of objects, but since I
  625. haven't thought of one I can't really request this...
  626.  
  627. Have fun all, and play safe! :-)
  628.    Peter.
  629.  
  630. ______________________________________________________________________
  631. Peter N Lewis, NCRPDA, Curtin University      peter@cujo.curtin.edu.au
  632. GPO Box U1987, Perth WA 6001, AUSTRALIA            FAX: +61 9 367 8141
  633.  
  634.  
  635.  
  636. ---------------------------
  637.  
  638. From: holwerda@sci.kun.nl (R.N.A. Holwerda)
  639. Subject: Mistake in THINK Pascal manual (boolean operators)
  640. Organization: University of Nijmegen, The Netherlands
  641. Date: Mon, 15 Jun 1992 14:25:25 GMT
  642.  
  643.  
  644.  
  645. Hi there,
  646.  
  647. The Think Pascal 4.0 Manual description of the behaveour of boolean operators
  648. is incorrect. It says that when your program evaluates
  649.  
  650.       boolexprA  and  boolexprB
  651.  
  652. you can't be sure boolexprB will be evaluated because the result of the 'and'-
  653. expression will be false if boolexprA eveluates to false. Then there's no need
  654. to evaluate boolexprB.
  655.  
  656. My tests indicate that this is incorrect. Even if boolexprA returns false, 
  657. boolexprB will be evaluated. The similar thing holds for the 'or' operator.
  658.  
  659. However, when I examined the TCL-source code I found out that there is an alter-
  660. native 'and'-operator called '&'. This operator behaves like the manual says 
  661. 'and' does. For the 'or' there's the alternative '|'.
  662.  
  663. But these operators are not mentioned in the manual! At least not in the section
  664. about operators.
  665.  
  666. Has anyone else found any errors like this in the manual, or other undocumented
  667. features of the language or the envrinment? I'd really like to know.
  668.  
  669.              Robert Holwerda,
  670.              holwerda@sci.kun.nl
  671.  
  672. P.S. Is there in internet address where I can report such things to Symantec?
  673.      I heard there is a platform for THINK C programmers.
  674.  
  675.  
  676. +++++++++++++++++++++++++++
  677.  
  678. From: greeny@top.cis.syr.edu (J. S. Greenfield)
  679. Organization: Syracuse University, CIS Dept.
  680. Date: Mon, 15 Jun 92 13:23:22 EDT
  681.  
  682. In article <1992Jun15.142525.12835@sci.kun.nl> holwerda@sci.kun.nl (R.N.A. Holwerda) writes:
  683. >
  684. >The Think Pascal 4.0 Manual description of the behaveour of boolean operators
  685. >is incorrect. It says that when your program evaluates
  686. >
  687. >      boolexprA  and  boolexprB
  688. >
  689. >you can't be sure boolexprB will be evaluated because the result of the 'and'-
  690. >expression will be false if boolexprA eveluates to false. Then there's no need
  691. >to evaluate boolexprB.
  692. >
  693. >My tests indicate that this is incorrect. Even if boolexprA returns false, 
  694. >boolexprB will be evaluated. The similar thing holds for the 'or' operator.
  695.  
  696. I believe that you have misread the manual.  The manual clearly does *not*
  697. state that a partial-evaluation semantics is used.  It states that a partial-
  698. evaluation semantics *may* be used, or may not--and as an end-user programmer,
  699. you are not able to predict which will occur.  Therefore, you are cautioned
  700. not to rely on either partial-evaluation or complete-evaluation semantics
  701. being performed.
  702.  
  703. Of course, only Symantec can answer why this has been done, but I would venture
  704. a guess that it was a matter of convenience for them.  Code optimization
  705. probably plays a large role in determining which boolean sub-expressions are
  706. evaluated first and whether or not an expression ends up being evaluated by
  707. (what appears to the programmer as) partial-evaluation semantics.
  708.  
  709.  
  710. - -- 
  711. J. S. Greenfield                                         greeny@top.cis.syr.edu
  712. (I like to put 'greeny' here, 
  713. but my d*mn system wants a 
  714. *real* name!)                        "What's the difference between an orange?"
  715.  
  716. +++++++++++++++++++++++++++
  717.  
  718. From: phils@chaos.cs.brandeis.edu (Phil Shapiro)
  719. Date: 16 Jun 92 15:03:53 GMT
  720. Organization: Symantec Corp.
  721.  
  722. >>>>> On Mon, 15 Jun 92 13:23:22 EDT, greeny@top.cis.syr.edu (J. S. Greenfield) said:
  723.  > In article <1992Jun15.142525.12835@sci.kun.nl> holwerda@sci.kun.nl (R.N.A. Holwerda) writes:
  724. >>
  725. >>The Think Pascal 4.0 Manual description of the behaveour of boolean
  726. >>operators is incorrect. It says that when your program evaluates
  727. >>
  728. >>      boolexprA  and  boolexprB
  729. >>
  730. >>you can't be sure boolexprB will be evaluated because the result of
  731. >>the 'and'- expression will be false if boolexprA eveluates to false.
  732. >>Then there's no need to evaluate boolexprB.
  733. >>
  734. >>My tests indicate that this is incorrect. Even if boolexprA returns
  735. >>false, boolexprB will be evaluated. The similar thing holds for the
  736. >>'or' operator.
  737.  
  738.  > I believe that you have misread the manual.  The manual clearly
  739.  > does *not* state that a partial-evaluation semantics is used.  It
  740.  > states that a partial- evaluation semantics *may* be used, or may
  741.  > not--and as an end-user programmer, you are not able to predict
  742.  > which will occur.  Therefore, you are cautioned not to rely on
  743.  > either partial-evaluation or complete-evaluation semantics being
  744.  > performed.
  745.  
  746.  > Of course, only Symantec can answer why this has been done, but I
  747.  > would venture a guess that it was a matter of convenience for them.
  748.  > Code optimization probably plays a large role in determining which
  749.  > boolean sub-expressions are evaluated first and whether or not an
  750.  > expression ends up being evaluated by (what appears to the
  751.  > programmer as) partial-evaluation semantics.
  752.  
  753. The language reference section of the THINK Pascal user manual is
  754. almost the same as the Pascal ANSI standard. In general, odd rules
  755. like the one above are straight from the standard. The Pascal
  756. standard, like the ANSI C one, frees the implementation from specifing
  757. evaluation order in a number of cases, including assignment and
  758. function arguments.  Pascal also leaves order of evaluation of Boolean
  759. expressions up to the implementation, which does allow for some code
  760. optimization.
  761.  
  762. The '&' and '|' operators are known as short-circuit boolean
  763. operators, and THINK Pascal's support for them is mentioned on p. 478
  764. and p. 492. They're also referenced in the index under "boolean".
  765.  
  766. To email to Symantec Languages support directly, try either
  767. D0152@Applelink.apple.com or 76666.2005@CompuServe.com.
  768.  
  769.     -phil
  770. - --
  771.    Phil Shapiro                                   Software Engineer
  772.    Language Products Group                     Symantec Corporation
  773.            Internet: phils@cs.brandeis.edu
  774.  
  775. +++++++++++++++++++++++++++
  776.  
  777. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  778. Organization: NCRPDA, Curtin University
  779. Date: Wed, 17 Jun 1992 04:40:52 GMT
  780.  
  781. In article <1992Jun15.142525.12835@sci.kun.nl>, holwerda@sci.kun.nl (R.N.A. Holwerda) writes:
  782.  
  783. >       boolexprA  and  boolexprB
  784.  
  785. > you can't be sure boolexprB will be evaluated because the result of the 'and'-
  786. > expression will be false if boolexprA eveluates to false. Then there's no need
  787. > to evaluate boolexprB.
  788.  
  789. My THINK Pascal 4.0 manual says this:
  790.  
  791. "Boolean operators are somewhat unique in that the result of the operation
  792. may often be determined by the examination of only one operand. For example,
  793. the expression
  794.  
  795. (b<>0) and (a/b>10)
  796.  
  797. is known to have the value false if b=0 regardeless of the value of a.
  798. However, the evaluation of the subexpression (a/b>10) %BOLD-ON% may or 
  799. may not %BOLD-OFF% be performed in the evaluation of this expression.
  800. It is therefore best to assume that it will and avoid this kind of 
  801. expression."
  802.  
  803. Thats fairly clear cut.  Of course it doesn't mention & and | here, nor
  804. are they mentioned in the index (as and is for example).  However, if
  805. you look up short-circuit, there is a reference to (of all things :)
  806. Appendix C "Porting to THINk Pascal" which says:
  807.  
  808. "Short circuit Booleans
  809. THINK Pascal uses & and | operators for minimum evaluation of boolean 
  810. expressions.  In this statement:
  811.  
  812. if (p<>nil) & (p^.name='') then ...
  813.  
  814. The second test (p^.name='') is performed only if the first test (p<>nil)
  815. evaluated to true."
  816.  
  817. I distictly remember reading in there somewhere that short circuit boolean
  818. operators have been around since before v4, perhaps since before 3?.  I
  819. looked but I couldn't find it anywhere, perhaps its in the TP3 manual...
  820.  
  821. Hands up who would like to see some more operators, like: BAND, BOR, BSL,
  822. etc as operators, and + on strings (Please someone give me + for strings!).
  823. Sigh, I remember the good old days when I programmed in Turbo Pascal on
  824. the PC many years back, it had all of them, not to mention static arrays...
  825.  
  826. > P.S. Is there in internet address where I can report such things to Symantec?
  827. >      I heard there is a platform for THINK C programmers.
  828.  
  829. Now there is a good question...
  830.    Peter.
  831.  
  832. ______________________________________________________________________
  833. Peter N Lewis, NCRPDA, Curtin University      peter@cujo.curtin.edu.au
  834. GPO Box U1987, Perth WA 6001, AUSTRALIA            FAX: +61 9 367 8141
  835.  
  836.  
  837.  
  838. +++++++++++++++++++++++++++
  839.  
  840. From: Bruce.Hoult@bbs.actrix.gen.nz
  841. Date: Wed, 17 Jun 1992 12:06:52 GMT
  842. Organization: Actrix Information Exchange
  843.  
  844. In article <1992Jun15.142525.12835@sci.kun.nl> holwerda@sci.kun.nl (R.N.A. Holwerda) writes:
  845. > Has anyone else found any errors like this in the manual, or other undocumented
  846. > features of the language or the envrinment? I'd really like to know.
  847.  
  848. The "problem" you described is the standard way for Pascal to work (on the
  849. Mac at any rate).  I'm not about to prove that it *isn't* documented in
  850. the manual though :-)
  851.  
  852.  
  853. Here's a genuine bug that I found in THINK Pascal 4.01: the alternative
  854. form for GetMouse taking two integer Var parameters instead of a point
  855. is no longer accepted -- a friend's program stopped compiling when she
  856. took it from version 3 to 4.
  857.  
  858. According to the manual (p144, from memory) it is supposed to still work --
  859. certainly the alternative forms of (Draw/Fill/Erase etc)(Rect/RoundRect/Oval
  860. etc) with four integers instead of a Rect still work (the ones I tried anyway).
  861.  
  862. - -- Bruce
  863. - -- 
  864. Bruce.Hoult@bbs.actrix.gen.nz   Twisted pair: +64 4 477 2116
  865. BIX: brucehoult                 Last Resort:  PO Box 4145 Wellington, NZ
  866. "Cray's producing a 200 MIPS personal computer with 64MB RAM and a 1 GB
  867. hard disk that fits in your pocket!"   "Great!  Is it PC compatable?"
  868.  
  869. ---------------------------
  870.  
  871. From: zaccone@rigel.cs.bucknell.edu (Rick Zaccone)
  872. Subject: Think C and ctype
  873. Date: 16 Jun 92 14:57:51 GMT
  874. Organization: Bucknell University, Lewisburg, Pa.
  875.  
  876. I'm trying to understand how Think C 5.0.2 implements the ctype
  877. library.
  878.  
  879. The file ctype.c includes ctype.h.  If I run the preprocessor on
  880. ctype.c I get the following definition for isalnum.  (Is this a
  881. function definition?)
  882.  
  883. - ----------------------------------------------------------------------
  884. int isalnum(int);
  885.  
  886. <Stuff Deleted>
  887.  
  888. extern char __ctype[];
  889. int
  890. (isalnum)(int c)
  891. {
  892. return((__ctype[(int) (unsigned char) (c)] & (64|128|16)));
  893. }
  894. - ----------------------------------------------------------------------
  895. If I create a test program that uses isalnum and then run it through
  896. the preprocessor, it gets expanded to the stuff returned by the
  897. "return".  So, Think C is (apparently) not using this function
  898. definition although it *does* produce object code for it!  (I verified
  899. this by just compiling this function.)  So what's going on here?  Is
  900. this just an intricate way of doing type checking for the macro
  901. parameters?  This looks somewhat like a function but I'm mystified by
  902. the "(isalnum)".  Is this a Think C extension to C?  I haven't been
  903. able to find it in the manual.
  904.  
  905. Rick Zaccone
  906. - --
  907. zaccone@bucknell.edu
  908.  
  909.  
  910. +++++++++++++++++++++++++++
  911.  
  912. From: suitti@ima.isc.com (Stephen Uitti)
  913. Organization: Interactive Systems, Cambridge, MA 02138-5302
  914. Date: Tue, 16 Jun 1992 18:28:47 GMT
  915.  
  916. In article <ZACCONE.92Jun16105751@rigel.cs.bucknell.edu> zaccone@bucknell.edu writes:
  917. >I'm trying to understand how Think C 5.0.2 implements the ctype
  918. >library.
  919. >
  920. >The file ctype.c includes ctype.h.  If I run the preprocessor on
  921. >ctype.c I get the following definition for isalnum.  (Is this a
  922. >function definition?)
  923. >
  924. >----------------------------------------------------------------------
  925. >int isalnum(int);
  926. >
  927. ><Stuff Deleted>
  928. >
  929. >extern char __ctype[];
  930. >int
  931. >(isalnum)(int c)
  932. >{
  933. >return((__ctype[(int) (unsigned char) (c)] & (64|128|16)));
  934. >}
  935. >----------------------------------------------------------------------
  936. >If I create a test program that uses isalnum and then run it through
  937. >the preprocessor, it gets expanded to the stuff returned by the
  938. >"return".  So, Think C is (apparently) not using this function
  939. >definition although it *does* produce object code for it!  (I verified
  940. >this by just compiling this function.)  So what's going on here?  Is
  941. >this just an intricate way of doing type checking for the macro
  942. >parameters?  This looks somewhat like a function but I'm mystified by
  943. >the "(isalnum)".
  944.  
  945. I recall that the ANSI C standard says that for these functions
  946. you must have a real function, even if you provide a macro version.
  947. That way, you can put function pointers to them into a table, and
  948. it will work.
  949.  
  950. Now then, there are good reasons to make ctype functions macros.
  951. Each of them does very little actual work.  The function call
  952. overhead would dominate.  In fact, I recall a versions of UNIX
  953. "spell" for the Vax, that spent over half of its time checking
  954. isupper(), and calling tolower().  When these calls were inlined,
  955. the spelling checker ran more than twice as fast (there were other
  956. things that could have been done to "spell", and I saw a rewrite
  957. that was over 8 times as fast).
  958.  
  959. For isalnum(), you could check to see if the character were alpha,
  960. by calling isalpha(), or numeric, by calling isdigit():
  961.  
  962. #define isalnum(x) (isalpha(x) || isdigit(x))
  963.  
  964. And isalpha() could be written for ASCII to check ranges:
  965.  
  966. #define isalpha(x) (((x) >= 'a' && (x) <= 'z') || ((x) >= 'a' && (x) <= 'z'))
  967.  
  968. And isdigit() could be written for ASCII to do a range check:
  969.  
  970. #define isdigit(x) ((x) >= '0' && (x) <= '9')
  971.  
  972. However, it is much faster to have a pre-computed array of flags, one
  973. byte per flag.  The character in question is used as an index into the
  974. array.  The array need be only 256 bytes long.  There can be 8 flags.
  975. One for "is this character a digit", one for "is this upper case",
  976. one for "is this lower case", etc.  This leads to a coding like:
  977.  
  978.     __ctype[(int) (unsigned char) (c)] & (64|128|16)));
  979.  
  980. The two underscores for the array are so that the name does not
  981. conflict with user code.  ANSI C says that identifiers beginning
  982. with two underscores are reserved for the system.  The "&" is checking
  983. for any of the specific bits set.  Since FALSE is 0, and TRUE
  984. is anything else, having isalnum() return 64 for some character
  985. is OK.
  986.  
  987. >...  Is this a Think C extension to C?  I haven't been
  988. >able to find it in the manual.
  989.  
  990. Think C certainly has extensions, but this isn't one of them.
  991. Page 208 of the standard library reference manual doesn't say
  992. that it is an extension, and it places the function in the ANSI
  993. library.  There is an error on page 208.  It claims that
  994.  
  995.     Each of these functions takes a single character c as an
  996.     argument.  It returns 1 if c is a member of the category,
  997.     and a non-zero value if c isn't.
  998.  
  999. It should say that it returns a non-zero (TRUE) value is c is a
  1000. member, and zero (FALSE) if c isn't.  Then, under Returns, page
  1001. 209, it gets it backwards:
  1002.  
  1003.     If c is...        The function returns...
  1004.     in the category        0 (zero).
  1005.     not in the category    non-zero.
  1006.  
  1007. When it should be:
  1008.  
  1009.     If c is...        The function returns...
  1010.     in the category        non-zero.
  1011.     not in the category    0 (zero).
  1012.  
  1013. At least the example is correct (and is indented using K&R style,
  1014. as God intended ;-).
  1015.  
  1016. Stephen.
  1017. suitti@ima.isc.com
  1018.  
  1019. +++++++++++++++++++++++++++
  1020.  
  1021. From: mkahl@world.std.com (Michael Kahl)
  1022. Date: 17 Jun 92 10:04:20 GMT
  1023. Organization: The World Public Access UNIX, Brookline, MA
  1024.  
  1025. In article <ZACCONE.92Jun16105751@rigel.cs.bucknell.edu> zaccone@bucknell.edu writes:
  1026. >I'm trying to understand how Think C 5.0.2 implements the ctype
  1027. >library.
  1028. >
  1029. >The file ctype.c includes ctype.h.  If I run the preprocessor on
  1030. >ctype.c I get the following definition for isalnum.  (Is this a
  1031. >function definition?)
  1032. >
  1033. >----------------------------------------------------------------------
  1034. >int isalnum(int);
  1035. >
  1036. ><Stuff Deleted>
  1037. >
  1038. >extern char __ctype[];
  1039. >int
  1040. >(isalnum)(int c)
  1041. >{
  1042. >return((__ctype[(int) (unsigned char) (c)] & (64|128|16)));
  1043. >}
  1044. >----------------------------------------------------------------------
  1045. >If I create a test program that uses isalnum and then run it through
  1046. >the preprocessor, it gets expanded to the stuff returned by the
  1047. >"return".  So, Think C is (apparently) not using this function
  1048. >definition although it *does* produce object code for it!  (I verified
  1049. >this by just compiling this function.)  So what's going on here?  Is
  1050. >this just an intricate way of doing type checking for the macro
  1051. >parameters?  This looks somewhat like a function but I'm mystified by
  1052. >the "(isalnum)".  Is this a Think C extension to C?  I haven't been
  1053. >able to find it in the manual.
  1054. >
  1055. >Rick Zaccone
  1056. >--
  1057. >zaccone@bucknell.edu
  1058.  
  1059. Though it is certainly unusual to see redundant parentheses surrounding a
  1060. name in a function definition, they do not affect the meaning.  However, if
  1061. they were omitted, the preprocessor would expand "isalnum" as a macro, just
  1062. as it does in the body.  When a function-like macro (i.e. one with arguments)
  1063. appears not followed by a left parenthesis, it is protected from expansion;
  1064. surrounding the name in parentheses is one way to accomplish this.  This is
  1065. not a THINK C extension; it is entirely according to the Standard.
  1066.  
  1067. The function definition is there, even though it is normally not used, in case
  1068. *you* use "isalnum" in such a way that it does not get macro-expanded.  The
  1069. Standard says there has to be a real function there, backing up the macro as
  1070. it were, to cover this case.
  1071.  
  1072. - -- 
  1073. Michael Kahl      mkahl@world.std.com
  1074. Disclaimer:  Whoa!  Did I say THAT??!
  1075.  
  1076. ---------------------------
  1077.  
  1078. From: zobkiw@world.std.com (Joe Zobkiw)
  1079. Subject: dynamic 2d arrays in THINK C?
  1080. Organization: The World Public Access UNIX, Brookline, MA
  1081. Date: Wed, 17 Jun 1992 01:14:50 GMT
  1082.  
  1083. Does anyone have any information on where I might find some code to
  1084. implement dynamic 2-dimensional arrays in THINK C? 1-dimensions are easy
  1085. (aka Ptr) but 2-dimensions are a bit tougher to deal with in a nice, easy
  1086. manner.
  1087.  
  1088. Thanks in advance :)
  1089.  
  1090.  
  1091. - -- 
  1092. - -- joe zobkiw                      Internet: zobkiw@world.std.com
  1093. - --                                      AOL: AFL Zobkiw  
  1094. - -- mac.synthesis.MIDI.THINK C.OOP
  1095. - -- asm.comm.networks.cool tunes...
  1096.  
  1097. +++++++++++++++++++++++++++
  1098.  
  1099. From: 9999cs02@uhdvx3 (Tina Marie!)
  1100. Organization: University of Houston-Downtown
  1101. Date: Wed, 17 Jun 1992 02:37:00 GMT
  1102.  
  1103. (Joe Zobkiw) writes...
  1104. >Does anyone have any information on where I might find some code to
  1105. >implement dynamic 2-dimensional arrays in THINK C? 1-dimensions are easy
  1106. >(aka Ptr) but 2-dimensions are a bit tougher to deal with in a nice, easy
  1107. >manner.
  1108. >Thanks in advance :)
  1109.     
  1110.     Well, I don't have a reference, and I am not sure how nice and easy
  1111. you want this, but what's wrong with a dymanic array of Ptr's?? Say, like:
  1112.  
  1113. typedef struct
  1114. {
  1115.      Ptr array[];
  1116. } niceType;
  1117.  
  1118.     You can then reference it as  (array[i])[j]....it doesn't get
  1119. much nicer or easier.
  1120.  
  1121.     Tina Marie Femea
  1122.     9999cs02@dt3.dt.uh.edu
  1123.  
  1124. +++++++++++++++++++++++++++
  1125.  
  1126. From: suitti@ima.isc.com (Stephen Uitti)
  1127. Organization: Interactive Systems, Cambridge, MA 02138-5302
  1128. Date: Wed, 17 Jun 1992 18:45:19 GMT
  1129.  
  1130. In article <Bpyu4r.1D8@world.std.com> zobkiw@world.std.com (Joe Zobkiw) writes:
  1131. >Does anyone have any information on where I might find some code to
  1132. >implement dynamic 2-dimensional arrays in THINK C? 1-dimensions are easy
  1133. >(aka Ptr) but 2-dimensions are a bit tougher to deal with in a nice, easy
  1134. >manner.
  1135.  
  1136. Here's a project that uses ANSI, oops libraries, one source, and
  1137. one header.  It isn't what you want, but you should be able to
  1138. get what you want from it.  It is developed in Think C 5.  You
  1139. need C + Objects turned on in the options.  It is lightly tested.
  1140. Consider it public, (no need to give credit, royalties, etc.).  Enjoy.
  1141.  
  1142. Stephen.
  1143. suitti@ima.isc.com
  1144.  
  1145. ####################
  1146.  
  1147. /* TwoDArray class header - two dimensional dynamic character array */
  1148.  
  1149. #ifndef _H_TWODARRAY
  1150. #define _H_TWODARRAY
  1151.  
  1152. struct TwoDArray : direct {
  1153.     short numArrays;    /* number of arrays */
  1154.     short *lengths;        /* array of lengths of each 1 D array */
  1155.     char **arrays;        /* pointers to arrays */
  1156.  
  1157.     /* Methods */
  1158.     void ITwoDArray(short y, short x);    /* init to y by x, x is fastest moving */
  1159.     void Dispose(void);
  1160.     void setvalue(short y, short x, char val);
  1161.     char getvalue(short y, short x);
  1162. };
  1163.  
  1164. #endif /* _H_TWODARRAY */
  1165.  
  1166. ####################
  1167.  
  1168. /* TwoDArray.c
  1169.  * Implement a two dimensional dynamic character array.
  1170.  */
  1171.  
  1172. #include "TwoDArray.h"
  1173.  
  1174. /* debug/test code */
  1175. #include <stdio.h>
  1176. #include <stdlib.h>
  1177.  
  1178. main()
  1179. {
  1180.     register i;
  1181.     register j;
  1182.  
  1183.     struct TwoDArray *two;
  1184.     two = new(TwoDArray);
  1185.     two->ITwoDArray(3, 5);
  1186.     for (i = 0; i < 3; i++) {
  1187.         for (j = 0; j < 5; j++) {
  1188.             two->setvalue(i, j, i * 10 + j);
  1189.         }
  1190.     }
  1191.     for (i = 0; i < 3; i++) {
  1192.         for (j = 0; j < 5; j++) {
  1193.             printf("%d ", two->getvalue(i, j));
  1194.         }
  1195.         printf("\n");
  1196.     }
  1197.     two->Dispose();
  1198. }
  1199.  
  1200. /* init to y by x, x is fastest moving */
  1201. void TwoDArray::ITwoDArray(short y, short x)
  1202. {
  1203.     register i;
  1204.  
  1205.     /* range check on y & x */
  1206.     if (x < 1 || y < 1) {
  1207.         printf("Range error in ITwoDArray\n");
  1208.         exit(1);
  1209.     }
  1210.     numArrays = y;
  1211.     if ((lengths = malloc(sizeof(short) * numArrays)) == NULL) {
  1212.         /* simple error check */
  1213.         printf("Out of memory in ITwoDArray\n");
  1214.         exit(1);
  1215.     }
  1216.     for (i = 0; i < numArrays; i++) {
  1217.         lengths[i] = x;
  1218.         if ((arrays[i] = malloc(x)) == NULL) {
  1219.             /* error check */
  1220.             printf("Out of memory in ITwoDArray\n");
  1221.             exit(1);
  1222.         }
  1223.     }
  1224. }
  1225.  
  1226. void TwoDArray::Dispose(void)
  1227. {
  1228.     register i;
  1229.     
  1230.     if (lengths != NULL) {
  1231.         free(lengths);
  1232.         lengths = NULL;
  1233.     }
  1234.     if (arrays != NULL) {
  1235.         for (i = 0; i < numArrays; i++) {
  1236.             if (arrays[i] != NULL) {
  1237.                 free(arrays[i]);
  1238.             }
  1239.         }
  1240.         free(arrays);
  1241.         arrays = NULL;
  1242.     }
  1243. }
  1244.  
  1245. void TwoDArray::setvalue(short y, short x, char val)
  1246. {
  1247.     if (y >= numArrays) {
  1248.         /* error check */
  1249.         printf("bad setvale - (%d, %d) = %d\n", y, x, val);
  1250.         return;
  1251.     }
  1252.     if (x >= lengths[y]) {
  1253.         /* error check */
  1254.         printf("bad setvale - (%d, %d) = %d\n", y, x, val);
  1255.         return;
  1256.     }
  1257.     arrays[y][x] = val;
  1258. }
  1259.     
  1260. char TwoDArray::getvalue(short y, short x)
  1261. {
  1262.     if (y >= numArrays) {
  1263.         /* error check */
  1264.         printf("bad getvale - (%d, %d) = %d\n", y, x);
  1265.         return;
  1266.     }
  1267.     if (x >= lengths[y]) {
  1268.         /* error check */
  1269.         printf("bad getvale - (%d, %d) = %d\n", y, x);
  1270.         return;
  1271.     }
  1272.     return arrays[y][x];
  1273. }
  1274.  
  1275.  
  1276. ####################
  1277.  
  1278. ---------------------------
  1279.  
  1280. End of C.S.M.P. Digest
  1281. **********************
  1282.